<?php
/**
 * chaotian
 * User: 申龙彪
 * Date: 2024-01-31
 * Time: 0:35
 */

namespace app\api\controller;

use app\common\controller\Api;

class Report extends Api
{
    protected $noNeedLogin = ['*'];

    public function sendReport()
    {
        $data = [
            'accout_or_nickname' => input('accout_or_nickname'),
            'issue' => input('issue'),
            'screenshot_images' => input('screenshot_images'),
        ];

        if (empty($data['accout_or_nickname'])) {
            $this->error('请输入用户ID/昵称');
        }

        $isExist = \app\admin\model\User::where('username', $data['accout_or_nickname'])
            ->whereOr('nickname', $data['accout_or_nickname'])
            ->count();

        if (!$isExist) {
            $this->error('输入的用户ID/昵称不存在');
        }

        if (empty($data['issue'])) {
            $this->error('请输入内容描述');
        }

        $model = new \app\common\model\Report();
        $res = $model->save($data);

        if ($res) {
            $this->success('提交成功');
        } else {
            $this->error('提交失败');
        }
    }
}
